package org.amq.server.controller;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;

import org.amq.base.util.ApplicationContextHolder;
import org.apache.activemq.web.LocalBrokerFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value = "")
public class IndexController {
    @Autowired
    LocalBrokerFacade localBrokerFacade;

    @RequestMapping(value = "")
    public String index1(Model model, HttpServletRequest request) {
        return "redirect:/admin/index.html";
    }

    @RequestMapping(value = "/monitor.html")
    public String monitor(Model model, HttpServletRequest request) {

        model.addAttribute("pageType", "none");
        return "monitor";
    }

    @RequestMapping(value = "/execute")
    public String monitor(Model model, String key, String value) throws SecurityException, NoSuchMethodException,
            IllegalArgumentException, IllegalAccessException, InvocationTargetException {
        Object obj = ApplicationContextHolder.getApplicationContext().getBean(key);
        Method method = obj.getClass().getMethod(value);
        method.invoke(obj);
        model.addAttribute("pageType", "none");
        return "monitor";
    }

}
